using System.Collections.Generic;

namespace DE.Sdc.SharePoint.SPContentStructure.Common
{
    public class HierarchicalList<TOwner, TItem> : IdentifierCollection<TItem> where TOwner : IHierarchicalElement where TItem : IHierarchicalElement
    {
        private TOwner _owner;
        public HierarchicalList()
        {
        }

        public HierarchicalList(TOwner owner)
        {
            Owner = owner;
        }

        public TOwner Owner
        {
            get { return _owner; }
            set
            {
                _owner = value;
                foreach (TItem item in this)
                {
                    item.Parent = Owner;
                }
            }
        }

        public new void Add(TItem item)
        {
            item.Parent = Owner;
            base.Add(item);
        }
    }
}